create or replace function upd_timestamp() returns trigger as
$$
begin
    new.modified = current_timestamp;
    return new;
end
$$
    language plpgsql;

CREATE DATABASE leaf;
CREATE TABLE "public"."leaf_alloc"
(
    "id"          bigserial PRIMARY KEY NOT NULL,
    "biz_tag"     varchar(128)          NOT NULL DEFAULT '',
    "max_id"      bigint                NOT NULL DEFAULT '1',
    "step"        int4                  NOT NULL,
    "description" varchar(256)                   DEFAULT NULL,
    "update_time" timestamp             NOT NULL DEFAULT current_timestamp
);

CREATE UNIQUE INDEX "uniq_biz_tag" ON "public"."leaf_alloc" USING btree ("biz_tag");

insert into leaf_alloc(biz_tag, max_id, step, description)
values ('leaf-segment-test', 1, 2000, 'Test leaf Segment Mode Get Id')